package com.haoxin.ai_course.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.haoxin.ai_course.common.annotation.SysLog;
import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.R;
import com.haoxin.ai_course.modules.sys.entity.SysDictType;
import com.haoxin.ai_course.modules.sys.service.SysDictTypeService;

import lombok.AllArgsConstructor;



/**
 * 字典类型表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-03-25 11:30:40
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sys/sysdicttype")
public class SysDictTypeController  extends AbstractController {
    private final  SysDictTypeService sysDictTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysdicttype:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        QueryWrapper<SysDictType> queryWrapper = new QueryWrapper<>();
        IPage<SysDictType> sysConfigList = sysDictTypeService.page(mpPageConvert.<SysDictType>pageParamConvert(params),queryWrapper);
        return R.ok().put("page", mpPageConvert.pageValueConvert(sysConfigList));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{dictId}")
    @RequiresPermissions("sys:sysdicttype:info")
    public R info(@PathVariable("dictId") Long dictId){
        return R.ok().put("sysDictType", sysDictTypeService.getById(dictId));
    }


    /**
     * 新增字典类型表
     */
    @SysLog("新增字典类型表数据")
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysdicttype:save")
    public R save(@RequestBody SysDictType sysDictType){
        sysDictTypeService.save(sysDictType);
        return R.ok();
    }


    /**
     * 修改
     */
    @SysLog("修改字典类型表数据")
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysdicttype:update")
    public R update(@RequestBody SysDictType sysDictType){
		sysDictTypeService.updateById(sysDictType);
        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("删除字典类型表数据")
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysdicttype:delete")
    public R delete(@RequestBody Long[] dictIds){
		sysDictTypeService.removeByIds(Arrays.asList(dictIds));
        return R.ok();
    }
	
}
